package com.ruoyi.project.jsrh.news.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.jsrh.news.domain.ZtNewsType;
import com.ruoyi.project.jsrh.news.service.IZtNewsTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/jsrh/news_type")
public class NewsTypeController extends BaseController{

    @Autowired
    private IZtNewsTypeService ztNewsTypeService;

    private String prefix = "jsrh/news_type";

//    @RequiresPermissions("jsrh:news_type:menu")
//    @GetMapping()
//    public String menu(){
//        return prefix + "/menu";
//    }


    @RequiresPermissions("jsrh:news_type:view")
    @GetMapping()
    public String type()
    {
        return prefix + "/type";
    }

    /**
     * 查询资讯所属类别列表
     */
    @RequiresPermissions("jsrh:news_type:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZtNewsType ztNewsType)
    {
        startPage();
        List<ZtNewsType> list = ztNewsTypeService.selectZtNewsTypeList(ztNewsType);
        return getDataTable(list);
    }

    /**
     * 导出资讯所属类别列表
     */
    @RequiresPermissions("jsrh:news_type:export")
    @Log(title = "资讯所属类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZtNewsType ztNewsType)
    {
        List<ZtNewsType> list = ztNewsTypeService.selectZtNewsTypeList(ztNewsType);
        ExcelUtil<ZtNewsType> util = new ExcelUtil<ZtNewsType>(ZtNewsType.class);
        return util.exportExcel(list, "type");
    }

    /**
     * 新增资讯所属类别
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存资讯所属类别
     */
    @RequiresPermissions("jsrh:news_type:add")
    @Log(title = "资讯所属类别", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZtNewsType ztNewsType)
    {
        return toAjax(ztNewsTypeService.insertZtNewsType(ztNewsType));
    }

    /**
     * 修改资讯所属类别
     */
    @GetMapping("/edit/{newsTypeId}")
    public String edit(@PathVariable("newsTypeId") Long newsTypeId, ModelMap mmap)
    {
        ZtNewsType ztNewsType = ztNewsTypeService.selectZtNewsTypeById(newsTypeId);
        mmap.put("ztNewsType", ztNewsType);
        return prefix + "/edit";
    }

    /**
     * 修改保存资讯所属类别
     */
    @RequiresPermissions("jsrh:news_type:edit")
    @Log(title = "资讯所属类别", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZtNewsType ztNewsType)
    {
        return toAjax(ztNewsTypeService.updateZtNewsType(ztNewsType));
    }

    /**
     * 删除资讯所属类别
     */
    @RequiresPermissions("jsrh:news_type:remove")
    @Log(title = "资讯所属类别", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ztNewsTypeService.deleteZtNewsTypeByIds(ids));
    }



}
